package com.example.java3mysql2.instrastructure;

import com.example.java3mysql2.domain.Student;
import com.example.java3mysql2.domain.Student_;
import com.example.java3mysql2.domain.dto.PureStudent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface JpaStudent extends JpaRepository<Student,Long>, JpaSpecificationExecutor<Student> {

    Student findByStudentCode(String code);

    List<Student> findByCommunity_CommunityCode(String code);
    @Query("select new com.example.java3mysql2.domain.dto.PureStudent(s.studentCode,s.studentName)" +
            " from Student s left join s.community c" +
            " where c.communityCode = ?1")
    List<PureStudent> queryViaCommunity_CommunityCode(String code);

    @Transactional
    void deleteByStudentCode(String code);
}
